package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.Role;
import com.indusfo.spc.pojo.RoleBO;
import com.indusfo.spc.pojo.RoleVO;
import com.indusfo.spc.service.RoleService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 角色信息表后台业务接口  
 * @author 贺闻博
 * 
 *   2018年11月29日
 */
@Controller
@RequestMapping("/role")
public class RoleController {
     
	@Autowired
	private RoleService roleService;
	/**
	 * 查询角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping(value="selectRoleS")
	@ResponseBody
	public JSONObject selectRoleS(Role role){
		JSONObject listRole = roleService.selectRoleS(role);
	  	return listRole;
	}
	/**
	 * 更新角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping(value = "updateRole")
	@ResponseBody
	public JSONObject updateRole(Role role){
		JSONObject num = roleService.updateRole(role);
		return num;
	}
	
	/**
	 * 新增角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping(value = "insertRole")
	//@RequiresPermissions("role:shiro:insert")
	@ResponseBody
	public JSONObject insertRole(Role role){
		JSONObject num = roleService.updateRole(role);
		return num;
	}

	/**
	 * 删除角色信息
	 * @param lRoleIds
	 * @param lDataState
	 * @return
	 */
	/*@RequestMapping(value="deleteRole")
	@RequiresPermissions("role:shiro:delete")
	@ResponseBody
	public JSONObject deleteRole(Long[] lRoleIds,Integer lDataState){
		Integer data = 2;
		String msg = "";
		try {
			msg = roleService.deleteRole(lRoleIds, data);
		} catch (GlobalException e) {
			return JSONObject.build(401,e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			return JSONObject.build(401, "服务器未知异常");
		}

		return JSONObject.oK(msg);
	}*/

	/**
	 * 启停角色信息
	 * @param lRoleIds
	 * @param lDataState
	 * @return
	 */
	/*@RequestMapping(value="definesRole")
	@RequiresPermissions("role:shiro:defines")
	@ResponseBody
	public JSONObject definesRole(Long[] lRoleIds,Integer lDataState){
		String msg = "";
		try {
			msg = roleService.deleteRole(lRoleIds, lDataState);
		} catch (GlobalException e) {
			return JSONObject.build(401,e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			return JSONObject.build(401, "服务器未知异常");
		}

		return JSONObject.oK(msg);
	}*/

	//---------------------------------- begin --------------------------------------//

	/**
	 * 根据角色ID查询权限列表
	 * 无ID，查询权限列表树(无勾选)，传入ID，查询权限列表树(该角色下的权限勾选状态)
	 *
	 * @param lRoleId 角色ID
	 * @return com.indusfo.spc.vo.JSONObject
	 * @author xuz
	 * @date 2019/7/17 1:53 PM
	 */
	@RequestMapping(value = "queryRoleVo")
	@ResponseBody
	public JSONObject queryRoleVO(Integer lRoleId) {
		RoleVO roleVO = roleService.queryRoleVO(lRoleId);
		return JSONObject.oK(roleVO);
	}

	/**
	 * 新增角色，及其他权限
	 *
	 * @author xuz
	 * @date 2019/7/9 4:09 PM
	 * @param roleBo
	 * @return com.indusfo.spc.vo.JSONObject
	 */
	@RequestMapping(value = "insertRoleBO")
	@ResponseBody
	public JSONObject insertRoleVo(@RequestBody RoleBO roleBo){
		String str = "";
		str = roleService.insertRoleVo(roleBo);
		return JSONObject.oK(str);
	}

	/**
	 * 更新角色，及其他权限
	 *
	 * @author xuz
	 * @date 2019/7/9 4:09 PM
	 * @param roleBo
	 * @return com.indusfo.spc.vo.JSONObject
	 */
	@RequestMapping(value = "updateRoleBO")
	@ResponseBody
	public JSONObject updateRoleVo(@RequestBody RoleBO roleBo){
		String str = "";
		str = roleService.updateRoleVO(roleBo);
		return JSONObject.oK(str);
	}

	/**
	 * 删除角色信息
	 * @param lRoleIds
	 * @return
	 */
	@RequestMapping(value="deleteRole")
	@ResponseBody
	public JSONObject deleteRole(Long[] lRoleIds){
		Integer data = 2;
		String msg = "";
		msg = roleService.deleteRole(lRoleIds, data);
		return JSONObject.oK(msg);
	}

	/**
	 * 启用角色信息
	 * @param lRoleIds
	 * @return
	 */
	@RequestMapping(value="startRole")
	@ResponseBody
	public JSONObject startRole(Long[] lRoleIds){
		Integer lDataState = 1;
		String msg = "";
		msg = roleService.deleteRole(lRoleIds, lDataState);
		return JSONObject.oK(msg);
	}

	/**
	 * 停用角色信息
	 * @param lRoleIds
	 * @return
	 */
	@RequestMapping(value="stopRole")
	@ResponseBody
	public JSONObject stopRole(Long[] lRoleIds){
		Integer lDataState = 3;
		String msg = "";
		msg = roleService.deleteRole(lRoleIds, lDataState);
		return JSONObject.oK(msg);
	}

	//---------------------------------- end --------------------------------------//
}
